package ms.aurora.util;

import java.util.Collection;
import java.util.Iterator;

/**
 * @author rvbiljouw
 */
public class PairIterator<O1, O2> {
    private Collection<O1> O1collection;
    private Collection<O2> O2collection;
    private Iterator<O1> O1iterator;
    private Iterator<O2> O2iterator;
    private O1 currentO1;
    private O2 currentO2;

    public PairIterator(Collection<O1> O1collection, Collection<O2> O2collection) {
        this.O1collection = O1collection;
        this.O2collection = O2collection;
        this.O1iterator = O1collection.iterator();
        this.O2iterator = O2collection.iterator();
    }

    public void reset() {
        O1iterator = O1collection.iterator();
        O2iterator = O2collection.iterator();
    }

    public boolean next() {
        if (O1iterator.hasNext() && O2iterator.hasNext()) {
            _next();
            return true;
        }
        return false;
    }

    private void _next() {
        currentO1 = O1iterator.next();
        currentO2 = O2iterator.next();
    }

    public O1 getFirst() {
        return currentO1;
    }

    public O2 getSecond() {
        return currentO2;
    }
}
